﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using StudentHookups.WCF;

namespace StudentHookups.Account
{
    public partial class MyProfile : System.Web.UI.Page
    {
        WCF.WCFClient client = new WCFClient();

        //These are hidden inside of loginView so reach them Find control is needed
        Label lblFullname = new Label();
        Label Accountname = new Label();
        Label Age = new Label();
        Label Gender = new Label();
        Image ProfileImage = new Image();
        TextBox tbInformation = new TextBox();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.IsAuthenticated)
            {
                Guid user = (Guid)Membership.GetUser().ProviderUserKey;
                UserComposite loggedinUser = client.GetUser(user);
                if ((loggedinUser == null))
                {
                    Response.Redirect("~/Account/Profile/EditProfile.aspx");
                }
                else
                {
                    if(!IsPostBack){
                    //Using find control to reach controls
                    lblFullname = (Label)MyProfileLogin.FindControl("Fullname");
                    Accountname = (Label)MyProfileLogin.FindControl("Accountname");
                    Age = (Label)MyProfileLogin.FindControl("Age");
                    Gender = (Label)MyProfileLogin.FindControl("Gender");
                    tbInformation = (TextBox)MyProfileLogin.FindControl("tbInfo");



                    lblFullname.Text = "<b>Fullname: </b>" + " " + loggedinUser.Firstname + " " + loggedinUser.Lastname;
                    Accountname.Text = "<b>Username: </b>" + " " + loggedinUser.Username;
                    Age.Text = "<b>Age: </b>" + " " + loggedinUser.Age.ToString();
                    Gender.Text = "<b>Gender: </b>" + " " + loggedinUser.Gender;
                    tbInformation.Text = loggedinUser.Information;



                    ProfileImage = (Image)MyProfileLogin.FindControl("ProfileImage");
                    ProfileImage.ImageUrl = loggedinUser.Image;
                }
                }
        }
            }


    }
}
    
